# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.db import models
from django.utils.translation import ugettext_lazy as _

class FriendshipRequest(models.Model):
  from_user = models.ForeignKey(User, related_name="invitations_from")
  to_user = models.ForeignKey(User, related_name="invitations_to")
  message = models.CharField(max_length=200, blank=True)

  class Meta:
    verbose_name = 'приглашение в друзья'
    verbose_name_plural = 'приглашения в друзья'
    #unique_together = (('to_user', 'from_user'),)

  def __unicode__(self):
    return _(u'%(from_user)s wants to be friends with %(to_user)s') % \
           {'from_user': unicode(self.from_user),
            'to_user': unicode(self.to_user)}

  def accept(self):
    self.from_user.user_info.friends.add(self.to_user)
    self.to_user.user_info.friends.add(self.from_user)
    self.delete()

  def decline(self):
    self.delete()

  def cancel(self):
    self.delete()
